package entitygeneralizationabstractleaf;

import java.util.Arrays;
import org.eclipse.viatra2.emf.incquery.runtime.api.IPatternMatch;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BasePatternMatch;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.Pattern;
import sysmodel.Entity;

/**
 * Pattern-specific match representation of the EntityGeneralizationAbstractLeaf pattern, 
 * to be used in conjunction with EntityGeneralizationAbstractLeafMatcher.
 * 
 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
 * Each instance is a (possibly partial) substitution of pattern parameters, 
 * usable to represent a match of the pattern in the result of a query, 
 * or to specify the bound (fixed) input parameters when issuing a query.
 * 
 * @see EntityGeneralizationAbstractLeafMatcher
 * @see EntityGeneralizationAbstractLeafProcessor
 * 
 */
public final class EntityGeneralizationAbstractLeafMatch extends BasePatternMatch implements IPatternMatch {
  private Entity fEntity;
  
  private static String[] parameterNames = {"entity"};
  
  public EntityGeneralizationAbstractLeafMatch(final Entity pEntity) {
    this.fEntity = pEntity;
    
  }
  
  @Override
  public Object get(final String parameterName) {
    if ("entity".equals(parameterName)) return this.fEntity;
    return null;
    
  }
  
  public Entity getEntity() {
    return this.fEntity;
    
  }
  
  @Override
  public boolean set(final String parameterName, final Object newValue) {
    if ("entity".equals(parameterName) && newValue instanceof sysmodel.Entity) {
    	this.fEntity = (sysmodel.Entity) newValue;
    	return true;
    }
    return false;
    
  }
  
  public void setEntity(final Entity pEntity) {
    this.fEntity = pEntity;
    
  }
  
  @Override
  public String patternName() {
    return "EntityGeneralizationAbstractLeaf";
    
  }
  
  @Override
  public String[] parameterNames() {
    return EntityGeneralizationAbstractLeafMatch.parameterNames;
    
  }
  
  @Override
  public Object[] toArray() {
    return new Object[]{fEntity};
    
  }
  
  @Override
  public String prettyPrint() {
    StringBuilder result = new StringBuilder();
    result.append("\"entity\"=" + prettyPrintValue(fEntity)
    );return result.toString();
    
  }
  
  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((fEntity == null) ? 0 : fEntity.hashCode()); 
    return result; 
    
  }
  
  @Override
  public boolean equals(final Object obj) {
    if (this == obj)
    	return true;
    if (obj == null)
    	return false;
    if (!(obj instanceof IPatternMatch))
    	return false;
    IPatternMatch otherSig  = (IPatternMatch) obj;
    if (!pattern().equals(otherSig.pattern()))
    	return false;
    if (!EntityGeneralizationAbstractLeafMatch.class.equals(obj.getClass()))
    	return Arrays.deepEquals(toArray(), otherSig.toArray());
    				EntityGeneralizationAbstractLeafMatch other = (EntityGeneralizationAbstractLeafMatch) obj;
    				if (fEntity == null) {if (other.fEntity != null) return false;}
    				else if (!fEntity.equals(other.fEntity)) return false;
    				return true;
    
  }
  
  @Override
  public Pattern pattern() {
    return EntityGeneralizationAbstractLeafMatcher.FACTORY.getPattern();
  }
}
